# 学生管理系统
students = {}  # 用字典存储学生信息，键为学号，值为学生信息元组


def insert_student():
    """添加学生"""
    student_id = input("请输入学号: ")
    if student_id in students:
        print("该学号已存在！")
        return

    name = input("请输入姓名: ")
    age = input("请输入年龄: ")
    grade = input("请输入班级: ")

    # 使用元组存储学生信息
    student_info = (name, age, grade)
    students[student_id] = student_info
    print(f"学生 {name} 添加成功！")


def delete_student():
    """删除学生"""
    id = input("请输入学生id : ")
    if id in students:
        url = input("是否删除",students[id][0],"y或n")
        if url == "y":
            del students[id]
            print(students[id][0],"删除成功")

        elif url == "n":
            print(students[id][0],"未删除")
            return
    return


def update_student():
    """修改学生信息"""
    id = input("请输入学生id : ")
    if id in students:
        url = input("是否修改", students[id][0], "y或n")
        if url == "y":
            name = input("请输入姓名: ")
            age = input("请输入年龄: ")
            grade = input("请输入班级: ")

            student_info = (name, age, grade)
            students[id] = student_info
            print(f"学生 {name} 修改成功！")

        elif url == "n":
            print(students[id][0], "未修改")
            return
    return


def select_student():
    """查询学生信息"""
    id = input("请输入学生编号: ")
    name = input("请输入要查询的学生姓名: ")
    if id in students and students[id][0] == name:
        print(f"学号: {id}, 姓名: {students[id][0]}, 年龄: {students[id][1]}, 班级: {students[id][2]}")
        return
    else:
        print("查无此人，请检查后重新输入")
        return


def display_all_students():
    """显示所有学生"""
    if not students:
        print("暂无学生信息！")
        return

    print("\n所有学生信息:")
    print("-" * 40)
    for student_id, student_info in students.items():
        print(f"学号: {student_id}, 姓名: {student_info[0]}, 年龄: {student_info[1]}, 班级: {student_info[2]}")
    print("-" * 40)


def main():
    """主函数"""
    while True:
        print("\n===== 学生管理系统 =====")
        print("1. 添加学生")
        print("2. 删除学生")
        print("3. 修改学生信息")
        print("4. 查询学生信息")
        print("5. 显示所有学生")
        print("0. 退出系统")

        choice = input("请选择操作: ")

        if choice == '1':
            insert_student()
        elif choice == '2':
            delete_student()
        elif choice == '3':
            update_student()
        elif choice == '4':
            select_student()
        elif choice == '5':
            display_all_students()
        elif choice == '0':
            print("感谢使用学生管理系统！")
            break
        else:
            print("无效选择，请重新输入！")


# 启动系统
if __name__ == "__main__":
    main()